package com.lanhu.designpattern.proxy.dynamicproxy.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 蓝狐
 */
public class HouseAgent implements InvocationHandler {

    private Person target;

    public Object getInstance(Person person){
        this.target = person;
        Class<?> clzz = target.getClass();
        return Proxy.newProxyInstance(clzz.getClassLoader(), clzz.getInterfaces(), this);
    }

    @Override
    public Object invoke (Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object invoke = method.invoke(this.target, args);
        after();
        return invoke;
    }

    public void before(){
        System.out.println("准备房源");
    }

    public void after(){
        System.out.println("是否满意,线下签合同");
    }
}
